home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / Other View Systems / PowerPlant PPob / FWPPobOb.cpp next >
Encoding:
Text File  |  1996-09-17  |  32.4 KB  |  998 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWPPobOb.cpp
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //========================================================================================
  8.  
  9. #ifndef FWPPOBOB_H
  10. #include "FWPPobOb.h"
  11. #endif
  12.  
  13. #ifndef FWSVIEW_H
  14. #include "FWSView.h"
  15. #endif
  16.  
  17. #ifndef FWFRAME_H
  18. #include "FWFrame.h"
  19. #endif
  20.  
  21. #ifndef FWSTATIC_H
  22. #include "FWStatic.h"
  23. #endif
  24.  
  25. #ifndef FWEDVIEW_H
  26. #include "FWEdView.h"
  27. #endif
  28.  
  29. #ifndef FWSCLBAR_H
  30. #include "FWSclBar.h"
  31. #endif
  32.  
  33. #ifndef FWSCROLR_H
  34. #include "FWScrolr.h"
  35. #endif
  36.  
  37. #ifndef FWPOPUP_H
  38. #include "FWPopup.h"
  39. #endif
  40.  
  41. #ifndef FWLISTBX_H
  42. #include "FWListBx.h"
  43. #endif
  44.  
  45. #ifndef FWCLUSTR_H
  46. #include "FWClustr.h"
  47. #endif
  48.  
  49. #ifndef FWTABBER_H
  50. #include "FWTabber.h"
  51. #endif
  52.  
  53. #ifndef FWUNKNOW_H
  54. #include "FWUnknow.h"
  55. #endif
  56.  
  57. #ifndef FWPICTSV_H
  58. #include "FWPictSv.h"
  59. #endif
  60.  
  61. //========================================================================================
  62. // PPob data structures
  63. //========================================================================================
  64. #pragma options align=mac68k
  65.  
  66. struct SPaneInfo {
  67.     long        paneID;
  68.     short        width;
  69.     short        height;
  70.     char        visible;
  71.     char        enabled;
  72.     char        bindings[4];    // SBooleanRect
  73.     long        left;            // Int32
  74.     long        top;            // Int32
  75.     long        userCon;
  76.     long        superView;
  77. };
  78.  
  79. typedef struct SViewInfo {
  80.     long        imageSize[2];        // SDimension32
  81.     long        scrollPos[2];        // SPoint32
  82.     long        scrollUnit[2];        // SPoint32
  83.     short        reconcileOverhang;
  84. } SViewInfo;
  85.  
  86. typedef struct    SControlInfo {
  87.     long        valueMessage;
  88.     long        value;
  89.     long        minValue;
  90.     long        maxValue;
  91. } SControlInfo;
  92.  
  93. typedef struct SScrollerInfo {
  94.     short        horizBarLeftIndent;
  95.     short        horizBarRightIndent;
  96.     short        vertBarTopIndent;
  97.     short        vertBarBottomIndent;
  98.     long        scrollingViewID;
  99. } SScrollerInfo;
  100.  
  101. typedef struct {
  102.     char        hasHorizScroll;
  103.     char        hasVertScroll;
  104.     char        hasGrow;
  105.     char        hasFocusBox;
  106.     long        doubleClickMessage;
  107.     short        textTraitsID;
  108.     short        LDEFid;
  109.     short        numberOfItems;
  110. } SListBoxInfo;
  111.  
  112. #pragma options align=reset
  113.  
  114. //========================================================================================
  115. // 
  116. //========================================================================================
  117.  
  118. #ifdef FW_BUILD_MAC
  119. #pragma segment fwppob
  120. #endif
  121.  
  122. //----------------------------------------------------------------------------------------
  123. //    FW_CPPobView::FW_CPPobView
  124. //----------------------------------------------------------------------------------------
  125.  
  126. FW_CPPobView::FW_CPPobView(Environment* ev, FW_CReadableStream& stream) 
  127. {
  128. FW_UNUSED(ev);
  129.     // Set superview to frame or last parent view loaded from stream
  130.     fSuperView = FW_CPPobReader::gDefaultSuperView;
  131.     
  132.     // Read PPob pane data
  133.     SPaneInfo    paneInfo;
  134.     stream.Read(&paneInfo, sizeof(SPaneInfo));
  135.  
  136.     fViewID = paneInfo.paneID;
  137.     
  138.     // ODF doesn't support 32 bit coordinates yet like PowerPlant
  139.     if (paneInfo.left > FW_MAXINT16 || paneInfo.left < FW_MININT16 ||
  140.         paneInfo.top > FW_MAXINT16  || paneInfo.top < FW_MININT16 ||
  141.         paneInfo.width > FW_MAXINT16 || paneInfo.height > FW_MAXINT16)
  142.             PPOB_WARNING("PPobReader Warning: found a view out of 16 bit space. ODF will adjust its bounds.");
  143.     // Manual corrections. This will make it easier to spot the offending views.
  144.     if (paneInfo.left > FW_MAXINT16)
  145.         paneInfo.left = 0;
  146.     if (paneInfo.left < FW_MININT16)
  147.         paneInfo.left = 0;
  148.     if (paneInfo.top > FW_MAXINT16)
  149.         paneInfo.top = 0;
  150.     if (paneInfo.top < FW_MININT16)
  151.         paneInfo.top = 0;
  152.     if (paneInfo.width > FW_MAXINT16)
  153.         paneInfo.width = FW_MAXINT16 / 2;
  154.     if (paneInfo.height > FW_MAXINT16)
  155.         paneInfo.height = FW_MAXINT16 / 2;
  156.     
  157.     FW_CPoint topLeft(FW_IntToFixed(paneInfo.left), FW_IntToFixed(paneInfo.top));
  158.     fBounds.Set(topLeft, FW_IntToFixed(paneInfo.width), FW_IntToFixed(paneInfo.height));
  159.     
  160.     // Bindings: PowerPlant defines only 4 flags, left, top, right, bottom
  161.     // Width and Height are fixed unless both flags are on in each direction
  162.     fBindings = FW_kFixedWidth + FW_kFixedHeight;    
  163.     if (paneInfo.bindings[0]) 
  164.         fBindings += FW_kLeftBinding;
  165.     if (paneInfo.bindings[1]) 
  166.         fBindings += FW_kTopBinding;
  167.     if (paneInfo.bindings[2]) 
  168.     {
  169.         fBindings += FW_kRightBinding;
  170.         if (paneInfo.bindings[0])
  171.             fBindings -= FW_kFixedWidth;    // left and right are bound
  172.     }
  173.     if (paneInfo.bindings[3]) 
  174.     {
  175.         fBindings += FW_kBottomBinding;
  176.         if (paneInfo.bindings[1])
  177.             fBindings -= FW_kFixedHeight;    // top and bottom are bound
  178.     }
  179. }
  180.  
  181. //----------------------------------------------------------------------------------------
  182. //    FW_CPPobView::Create
  183. //----------------------------------------------------------------------------------------
  184. /**
  185. void*    FW_CPPobView::Create(FW_CReadableStream& stream, long type)
  186. {
  187. FW_UNUSED(type);
  188.     return (new FW_CPPobView(ev, stream));
  189. }
  190. **/
  191.  
  192. //----------------------------------------------------------------------------------------
  193. //    FW_CPPobView::CreateODFView
  194. //----------------------------------------------------------------------------------------
  195.  
  196. void    FW_CPPobView::CreateODFView(Environment* ev)
  197. {
  198. FW_UNUSED(ev);
  199.     PPOB_WARNING("FW_CPPobView::CreateODFView should not be called");
  200. /**
  201.     FW_CView* view = new FW_CView (ev, fSuperView, fBounds, fViewID);
  202.     view->SetBindings(ev, fBindings);
  203.     
  204.     delete this;    // we don't need you anymore...
  205. **/
  206. }
  207.  
  208. //----------------------------------------------------------------------------------------
  209. //    FW_CPPobSuperView::FW_CPPobSuperView
  210. //----------------------------------------------------------------------------------------
  211.  
  212. FW_CPPobSuperView::FW_CPPobSuperView(Environment* ev, FW_CReadableStream& stream) :
  213.     FW_CPPobView(ev, stream),
  214.     fIsContentView(false),
  215.     fScrollingDirection(FW_kNoScrolling)
  216. {
  217.     // Read LView data
  218.     SViewInfo    viewInfo;
  219.     stream.Read(&viewInfo, sizeof(SViewInfo));
  220.     
  221.     // Set the extent with the PP imageSize
  222.     long width = viewInfo.imageSize[0];
  223.     long height = viewInfo.imageSize[1];
  224.     
  225.     if (width > FW_MAXINT16 || height > FW_MAXINT16)
  226.             PPOB_WARNING("PPobReader Warning: view imageSize is too big. ODF will adjust its extent.");
  227.     if (width > FW_MAXINT16)
  228.         width = FW_MAXINT16 / 2;
  229.     if (height > FW_MAXINT16)
  230.         height = FW_MAXINT16 / 2;
  231.             
  232.     fExtent.Set(FW_IntToFixed(width), FW_IntToFixed(height));
  233.     
  234.     // if there is a scrolling view it must become the content view
  235.     if (FW_CPPobReader::gScroller != 0 &&
  236.             fViewID == FW_CPPobReader::gScroller->fScrollingViewID)
  237.     {    
  238.         // We adjust the content view use to the size and location of the scroller
  239.         // This avoids having to adjust the LView inside the LScroller in Constructor
  240.  
  241.         fBounds = FW_CPPobReader::gScroller->fBounds;
  242.         
  243.         // Handle case when the scroller takes the whole window (left and top are -1). 
  244.         if (fBounds.left < FW_kFixed0)
  245.             fBounds.left = FW_kFixed0;
  246.         if (fBounds.top < FW_kFixed0)
  247.             fBounds.top = FW_kFixed0;
  248.         
  249.         fBindings = FW_CPPobReader::gScroller->fBindings;
  250.         
  251.         // Check for horiz and vert scroll bars
  252.         if (FW_CPPobReader::gScroller->fHorizBarLeftIndent >= 0)
  253.         {
  254.             fScrollingDirection = FW_EScrollingDirection(fScrollingDirection | FW_kXScrolling);
  255.             fBounds.bottom -= FW_IntToFixed(16);    // space for horizontal scrollbar
  256.         }
  257.         if (FW_CPPobReader::gScroller->fVertBarTopIndent >= 0)
  258.         {
  259.             fScrollingDirection = FW_EScrollingDirection(fScrollingDirection | FW_kYScrolling);
  260.             fBounds.right -= FW_IntToFixed(16);        // space for vertical scrollbar
  261.         }
  262.         
  263.         fIsContentView = true;
  264.     }
  265. }
  266.  
  267. //----------------------------------------------------------------------------------------
  268. //    FW_CPPobSuperView::Create
  269. //----------------------------------------------------------------------------------------
  270.  
  271. void*    FW_CPPobSuperView::Create(Environment*ev, FW_CReadableStream& stream, long type)
  272. {
  273. FW_UNUSED(type);
  274.     return (new FW_CPPobSuperView(ev, stream));
  275. }
  276.  
  277. //----------------------------------------------------------------------------------------
  278. //    FW_CPPobSuperView::CreateODFView
  279. //----------------------------------------------------------------------------------------
  280.  
  281. void    FW_CPPobSuperView::CreateODFView(Environment* ev)
  282. {
  283.     // Create the ODF superview
  284.     FW_CSuperView* view = new FW_CSuperView(ev, fSuperView, fBounds, fViewID, fExtent, 
  285.                                         fScrollingDirection);
  286.     view->SetBindings(ev, fBindings);
  287.     
  288.     PostCreateODFView(ev, view);
  289.     
  290.     delete this;    // we don't need you anymore...
  291. }
  292.  
  293. //----------------------------------------------------------------------------------------
  294. //    FW_CPPobSuperView::PostCreateODFView
  295. //----------------------------------------------------------------------------------------
  296.  
  297. void    FW_CPPobSuperView::PostCreateODFView(Environment* ev, FW_CSuperView* view)
  298. {
  299.     // Make it the default superview for nested views
  300.     FW_CPPobReader::gDefaultSuperView = view;
  301.  
  302.     if (fIsContentView)
  303.     {
  304.         FW_ASSERT(FW_CPPobReader::gScroller != 0);
  305.         FW_CFrame* frame = view->GetFrame(ev);
  306.         if (frame->IsContentView(ev) == false)
  307.         {
  308.             PPOB_WARNING("PPobReader Warning: found more than 1 scrolling view");
  309.         }
  310.         else
  311.         {            
  312.             // Declare the content view and the scroller
  313.             view->BecomeContentView(ev);
  314.             
  315.             FW_CScroller* scroller = (FW_CScroller*)FW_CPPobReader::gScroller->fODFScroller;
  316.             FW_ASSERT(scroller != 0);
  317.             view->GetFrame(ev)->AdoptScroller(ev, scroller);
  318.         }
  319.         // Now we don't need our FW_CPPobScrollBarScroller object anymore
  320.         delete FW_CPPobReader::gScroller;
  321.         FW_CPPobReader::gScroller = 0;
  322.     }
  323. }
  324.  
  325. //----------------------------------------------------------------------------------------
  326. //    FW_CPPobEditView::FW_CPPobEditView
  327. //----------------------------------------------------------------------------------------
  328. FW_DEFINE_AUTO(FW_CPPobEditView)
  329.  
  330. FW_CPPobEditView::FW_CPPobEditView(Environment*ev, FW_CReadableStream& stream) :
  331.     FW_CPPobView(ev, stream)
  332. {    
  333.     fText = FW_CPPobReader::ReadStr255(stream);
  334.     stream >> fTextTraitsID >> fMaxChars >> fAttributes >> fKeyFilterID;
  335. }
  336.  
  337. //----------------------------------------------------------------------------------------
  338. //    FW_CPPobEditView::Create
  339. //----------------------------------------------------------------------------------------
  340.  
  341. void*    FW_CPPobEditView::Create(Environment*ev, FW_CReadableStream& stream, long type)
  342. {
  343. FW_UNUSED(type);
  344.     return FW_NEW(FW_CPPobEditView, (ev, stream));
  345. }
  346.  
  347. //----------------------------------------------------------------------------------------
  348. //    FW_CPPobEditView::CreateODFView
  349. //----------------------------------------------------------------------------------------
  350.  
  351. enum {    // from Powerplant's LEditField.h
  352.     editAttr_Box            = 0x80,
  353.     editAttr_WordWrap        = 0x40,
  354.     editAttr_AutoScroll        = 0x20,
  355.     editAttr_TextBuffer        = 0x10,
  356.     editAttr_OutlineHilite    = 0x08,
  357.     editAttr_InlineInput    = 0x04,
  358.     editAttr_TextServices    = 0x02
  359. };
  360.  
  361. void    FW_CPPobEditView::CreateODFView(Environment* ev)
  362. {
  363.     FW_TextBoxOptions options;
  364.     FW_CFont font;
  365.     FW_CColor color;
  366.     FW_CPPobReader::GetTextTraits(fTextTraitsID, font, options, color);
  367.  
  368.     unsigned short attributes = 0;
  369.     if (fAttributes & editAttr_Box)
  370.         attributes += FW_CEditView::kDrawBox;
  371.     if (fAttributes & editAttr_WordWrap)
  372.         attributes += FW_CEditView::kWordWrap;
  373.     if (fAttributes & editAttr_AutoScroll)
  374.         attributes += FW_CEditView::kAutoScroll;
  375.     if (fAttributes & editAttr_TextBuffer)
  376.         attributes += FW_CEditView::kTextBuffering;
  377.     if (fAttributes & editAttr_OutlineHilite)
  378.         attributes += FW_CEditView::kOutlineHilite;
  379.     if (fAttributes & editAttr_InlineInput)
  380.         attributes += FW_CEditView::kInlineInput;
  381.     if (fAttributes & editAttr_TextServices)
  382.         attributes += FW_CEditView::kTextServices;
  383.     
  384.     FW_CEditView* view = FW_NEW(FW_CEditView, (ev, fSuperView, fBounds, fViewID, fText, 
  385.                                                 font, fMaxChars, attributes));
  386.     view->SetBindings(ev, fBindings);
  387.  
  388.     delete this;    // we don't need you anymore...
  389. }
  390.  
  391. //----------------------------------------------------------------------------------------
  392. //    FW_CPPobTextEdit::FW_CPPobTextEdit
  393. //----------------------------------------------------------------------------------------
  394. FW_DEFINE_AUTO(FW_CPPobTextEdit)
  395.  
  396. FW_CPPobTextEdit::FW_CPPobTextEdit(Environment*ev, FW_CReadableStream& stream) :
  397.     FW_CPPobSuperView(ev, stream)
  398. {    
  399.     ResIDT initialTextID;
  400.     
  401.     stream >> fAttributes >> fTextTraitsID >> initialTextID;
  402.     
  403.     Handle    textHdl = ::GetResource('TEXT', initialTextID);
  404.     if (textHdl)
  405.     {
  406.         ::HLock(textHdl);
  407.         fText.ReplaceAll(*textHdl, ::GetHandleSize(textHdl));
  408.         ::HUnlock(textHdl);
  409.         ::ReleaseResource(textHdl);
  410.     }
  411. }
  412.  
  413. //----------------------------------------------------------------------------------------
  414. //    FW_CPPobTextEdit::Create
  415. //----------------------------------------------------------------------------------------
  416.  
  417. void*    FW_CPPobTextEdit::Create(Environment*ev, FW_CReadableStream& stream, long type)
  418. {
  419. FW_UNUSED(type);
  420.     return FW_NEW(FW_CPPobTextEdit, (ev, stream));
  421. }
  422.  
  423. //----------------------------------------------------------------------------------------
  424. //    FW_CPPobTextEdit::CreateODFView
  425. //----------------------------------------------------------------------------------------
  426.  
  427. enum {
  428.     textAttr_MultiStyle        = 0x8000,
  429.     textAttr_Editable        = 0x4000,
  430.     textAttr_Selectable        = 0x2000,
  431.     textAttr_WordWrap        = 0x1000
  432. };
  433.  
  434. void    FW_CPPobTextEdit::CreateODFView(Environment* ev)
  435. {
  436.     FW_TextBoxOptions options;
  437.     FW_CFont font;
  438.     FW_CColor color;
  439.     FW_CPPobReader::GetTextTraits(fTextTraitsID, font, options, color);
  440.  
  441.     unsigned short attributes = FW_CEditView::kDrawBox + FW_CEditView::kAutoScroll;
  442.     if (fAttributes & textAttr_WordWrap)
  443.         attributes += FW_CEditView::kWordWrap;
  444.     
  445.     // ODF doesn't have scrolling text views yet, so we can only create an FW_CEditView
  446.     // (see ODF Form for an example of scrolling text view mapping to LTextEdit)
  447.         
  448.     FW_CEditView* view = FW_NEW(FW_CEditView, (ev, fSuperView, fBounds, fViewID, fText, 
  449.                                                 font, -1, attributes));
  450.     view->SetBindings(ev, fBindings);
  451.  
  452.     // We ignore the scroller which may be containing this LTextEdit and we DON'T call
  453.     // FW_CPPobSuperView::PostCreateODFView.
  454.     if (FW_CPPobReader::gScroller)
  455.     {
  456.         delete FW_CPPobReader::gScroller->fODFScroller;
  457.         delete FW_CPPobReader::gScroller;
  458.         FW_CPPobReader::gScroller = 0;
  459.     }
  460.     
  461.     delete this;    // we don't need you anymore...
  462. }
  463.  
  464. //----------------------------------------------------------------------------------------
  465. //    FW_CPPobStaticText::FW_CPPobStaticText
  466. //----------------------------------------------------------------------------------------
  467. FW_DEFINE_AUTO(FW_CPPobStaticText)
  468.  
  469. FW_CPPobStaticText::FW_CPPobStaticText(Environment*ev, FW_CReadableStream& stream) :
  470.     FW_CPPobView(ev, stream)
  471. {    
  472.     fText = FW_CPPobReader::ReadStr255(stream);
  473.     stream >> fTextTraitsID;
  474. }
  475.  
  476. //----------------------------------------------------------------------------------------
  477. //    FW_CPPobStaticText::Create
  478. //----------------------------------------------------------------------------------------
  479.  
  480. void*    FW_CPPobStaticText::Create(Environment*ev, FW_CReadableStream& stream, long type)
  481. {
  482. FW_UNUSED(type);
  483.     return FW_NEW(FW_CPPobStaticText, (ev, stream));
  484. }
  485.  
  486. //----------------------------------------------------------------------------------------
  487. //    FW_CPPobStaticText::CreateODFView
  488. //----------------------------------------------------------------------------------------
  489.  
  490. void    FW_CPPobStaticText::CreateODFView(Environment* ev)
  491. {
  492.     FW_TextBoxOptions options;
  493.     FW_CFont font;
  494.     FW_CColor color;
  495.     FW_CPPobReader::GetTextTraits(fTextTraitsID, font, options, color);
  496.     options |= FW_kTextBoxClipToBox | FW_kTextBoxWordWrap;
  497.     FW_CInk textInk(color, FW_kRGBWhite, FW_kOr);
  498.     
  499.     // [LSD] FW_CStaticText ignores the viewID for now
  500.     FW_CStaticText* view = FW_NEW(FW_CStaticText, (ev, fSuperView, fBounds, fViewID, fText, font,
  501.                                                                     options, textInk));
  502.     view->SetBindings(ev, fBindings);
  503.  
  504.     delete this;    // we don't need you anymore...
  505. }
  506.  
  507. //----------------------------------------------------------------------------------------
  508. //    FW_CPPobGroupBox::FW_CPPobGroupBox
  509. //----------------------------------------------------------------------------------------
  510. FW_DEFINE_AUTO(FW_CPPobGroupBox)
  511.  
  512. FW_CPPobGroupBox::FW_CPPobGroupBox(Environment*ev, FW_CReadableStream& stream) :
  513.     FW_CPPobStaticText(ev, stream)
  514. {    
  515.     // Same data as a StaticText
  516. }
  517.  
  518. //----------------------------------------------------------------------------------------
  519. //    FW_CPPobGroupBox::Create
  520. //----------------------------------------------------------------------------------------
  521.  
  522. void*    FW_CPPobGroupBox::Create(Environment*ev, FW_CReadableStream& stream, long type)
  523. {
  524. FW_UNUSED(type);
  525.     return FW_NEW(FW_CPPobGroupBox, (ev, stream));
  526. }
  527.  
  528. //----------------------------------------------------------------------------------------
  529. //    FW_CPPobGroupBox::CreateODFView
  530. //----------------------------------------------------------------------------------------
  531.  
  532. void    FW_CPPobGroupBox::CreateODFView(Environment* ev)
  533. {
  534.     FW_TextBoxOptions options;
  535.     FW_CFont font;
  536.     FW_CColor color;
  537.     FW_CPPobReader::GetTextTraits(fTextTraitsID, font, options, color);
  538.     options |= FW_kTextBoxClipToBox | FW_kTextBoxWordWrap;
  539.     FW_CInk textInk(color, FW_kRGBWhite, FW_kOr);
  540.     
  541.     FW_CGroupBox* view = FW_NEW(FW_CGroupBox, (ev, fSuperView, fBounds, fViewID, fText, font, 
  542.                                             options, textInk, color));
  543.     view->SetBindings(ev, fBindings);
  544.  
  545.     delete this;    // we don't need you anymore...
  546. }
  547. //----------------------------------------------------------------------------------------
  548. //    FW_CPPobControl::FW_CPPobControl
  549. //----------------------------------------------------------------------------------------
  550.  
  551. FW_CPPobControl::FW_CPPobControl(Environment*ev, FW_CReadableStream& stream) :
  552.     FW_CPPobView(ev, stream)
  553. {    
  554.     SControlInfo    controlInfo;
  555.     stream.Read(&controlInfo, sizeof(SControlInfo));
  556.  
  557.     fMessage = controlInfo.valueMessage;
  558.     fValue = controlInfo.value;
  559.     fMinValue = controlInfo.minValue;
  560.     fMaxValue = controlInfo.maxValue;
  561. }
  562.  
  563. //----------------------------------------------------------------------------------------
  564. //    FW_CPPobControl::Create
  565. //----------------------------------------------------------------------------------------
  566. /**
  567. void*    FW_CPPobControl::Create(FW_CReadableStream& stream, long type)
  568. {
  569. FW_UNUSED(type);
  570.     return (new FW_CPPobControl(ev, stream));
  571. }
  572.  
  573. //----------------------------------------------------------------------------------------
  574. //    FW_CPPobControl::CreateODFView
  575. //----------------------------------------------------------------------------------------
  576.  
  577. void    FW_CPPobControl::CreateODFView(Environment* ev)
  578. {
  579.     FW_CControl* view = FW_NEW(FW_CControl, (ev, fSuperView, fViewID, fBounds, fMessage, fValue));
  580.     view->SetBindings(ev, fBindings);
  581.  
  582.     delete this;    // we don't need you anymore...
  583. }
  584. **/
  585.  
  586. //----------------------------------------------------------------------------------------
  587. //    FW_CPPobButton::FW_CPPobButton
  588. //----------------------------------------------------------------------------------------
  589. FW_DEFINE_AUTO(FW_CPPobButton)
  590.  
  591. FW_CPPobButton::FW_CPPobButton(Environment* ev, FW_CReadableStream& stream) :
  592.     FW_CPPobControl(ev, stream)
  593. {
  594.     // [LSD] We read LStdControl data here instead of in FW_CNativeControl because
  595.     //         the class fields don't match.  Same as in Popup menu
  596.  
  597.     short    controlKind;
  598.     long    macRefCon;
  599.     
  600.     stream >> controlKind >> fTextTraitsID;
  601.  
  602.     fLabel = FW_CPPobReader::ReadStr255(stream);
  603.     
  604.     stream >> macRefCon;    // not used by ODF
  605.  
  606.     // Translation to ODF fields
  607.  
  608.     if (controlKind == checkBoxProc)
  609.         fKind = FW_kCheckButton;
  610.     else if (controlKind == radioButProc)
  611.         fKind = FW_kRadioButton;
  612.     else 
  613.         fKind = FW_kPushButton;
  614.     
  615.     // Special case of default and cancel buttons in dialogs
  616.     
  617.     if (FW_CPPobReader::gDefaultButtonID != 0 &&
  618.             FW_CPPobReader::gDefaultButtonID == fViewID)
  619.     {
  620.         fKind = FW_kDefaultPushButton;
  621.         fMessage = FW_kDefaultButtonMsg;
  622.         FW_CPPobReader::gDefaultButtonID = 0; 
  623.     }
  624.     if (FW_CPPobReader::gCancelButtonID != 0 &&
  625.             FW_CPPobReader::gCancelButtonID == fViewID)
  626.     {
  627.         fMessage = FW_kCancelButtonMsg;
  628.         FW_CPPobReader::gCancelButtonID = 0; 
  629.     }
  630. }
  631.  
  632. //----------------------------------------------------------------------------------------
  633. //    FW_CPPobButton::Create
  634. //----------------------------------------------------------------------------------------
  635.  
  636. void*    FW_CPPobButton::Create(Environment*ev, FW_CReadableStream& stream, long type)
  637. {
  638. FW_UNUSED(type);
  639.     return FW_NEW(FW_CPPobButton, (ev, stream));
  640. }
  641.  
  642. //----------------------------------------------------------------------------------------
  643. //    FW_CPPobButton::CreateODFView
  644. //----------------------------------------------------------------------------------------
  645.  
  646. void    FW_CPPobButton::CreateODFView(Environment* ev)
  647. {
  648.     FW_TextBoxOptions options;
  649.     FW_CFont font;
  650.     FW_CColor color;
  651.     FW_CPPobReader::GetTextTraits(fTextTraitsID, font, options, color);
  652.  
  653.     FW_CButton* view = FW_NEW(FW_CButton, 
  654.                 (ev, fSuperView, fBounds, fViewID, fKind, fLabel, font, fMessage, fValue));
  655.     view->SetBindings(ev, fBindings);
  656.  
  657.     delete this;    // we don't need you anymore...
  658. }
  659.  
  660. //----------------------------------------------------------------------------------------
  661. //    FW_CPPobPopupMenu::FW_CPPobPopupMenu
  662. //----------------------------------------------------------------------------------------
  663. FW_DEFINE_AUTO(FW_CPPobPopupMenu)
  664.  
  665. FW_CPPobPopupMenu::FW_CPPobPopupMenu(Environment* ev, FW_CReadableStream& stream) :
  666.     FW_CPPobControl(ev, stream)
  667. {
  668.     // [LSD] We read LStdControl data here instead of in FW_CNativeControl because
  669.     //         the class fields don't match.  Same as in Button
  670.  
  671.     stream >> fControlKind >> fTextTraitsID;
  672.  
  673.     fLabel = FW_CPPobReader::ReadStr255(stream);
  674.     
  675.     stream >> fRefCon;    
  676.  
  677.     stream >> fInitialItem;
  678. }
  679.  
  680. //----------------------------------------------------------------------------------------
  681. //    FW_CPPobPopupMenu::Create
  682. //----------------------------------------------------------------------------------------
  683.  
  684. void*    FW_CPPobPopupMenu::Create(Environment*ev, FW_CReadableStream& stream, long type)
  685. {
  686. FW_UNUSED(type);
  687.     return FW_NEW(FW_CPPobPopupMenu, (ev, stream));
  688. }
  689.  
  690. //----------------------------------------------------------------------------------------
  691. //    FW_CPPobPopupMenu::CreateODFView
  692. //----------------------------------------------------------------------------------------
  693.  
  694. void    FW_CPPobPopupMenu::CreateODFView(Environment* ev)
  695. {
  696.     FW_TextBoxOptions options;
  697.     FW_CFont font;
  698.     FW_CColor color;
  699.     FW_CPPobReader::GetTextTraits(fTextTraitsID, font, options, color);
  700.  
  701.     // MenuID and titleWidth were stored in the MinValue & MaxValue fields of Control
  702.     FW_CPopupMenu* view = FW_NEW(FW_CPopupMenu, (ev, fSuperView, fBounds, fViewID,
  703.                  fMinValue, fLabel, fMaxValue, fInitialItem, 0, font, fRefCon));
  704.     view->SetBindings(ev, fBindings);
  705.  
  706.     delete this;    // we don't need you anymore...
  707. }
  708.  
  709. //----------------------------------------------------------------------------------------
  710. //    FW_CPPobScrollBarScroller::FW_CPPobScrollBarScroller
  711. //----------------------------------------------------------------------------------------
  712. // LScroller derives from LView in PowerPlant, so we must read the LView data first
  713.  
  714. FW_CPPobScrollBarScroller::FW_CPPobScrollBarScroller(Environment* ev, 
  715.                                     FW_CReadableStream& stream, FW_Boolean liveScrolling) :
  716.     FW_CPPobSuperView(ev, stream),
  717.     fLiveScrolling(liveScrolling),
  718.     fODFScroller(0)
  719. {
  720.     // Keep globale around to create the content view later
  721.     FW_CPPobReader::gScroller = this;
  722.     
  723.     SScrollerInfo    scrollerInfo;
  724.     stream.Read(&scrollerInfo, sizeof(SScrollerInfo));
  725.  
  726.     fHorizBarLeftIndent = scrollerInfo.horizBarLeftIndent;
  727.     fHorizBarRightIndent = scrollerInfo.horizBarRightIndent;
  728.     fVertBarTopIndent = scrollerInfo.vertBarTopIndent;
  729.     fVertBarBottomIndent = scrollerInfo.vertBarBottomIndent;
  730.     fScrollingViewID = scrollerInfo.scrollingViewID;
  731. }
  732.  
  733. //----------------------------------------------------------------------------------------
  734. //    FW_CPPobScrollBarScroller::Create
  735. //----------------------------------------------------------------------------------------
  736.  
  737. void*    FW_CPPobScrollBarScroller::Create(Environment*ev, FW_CReadableStream& stream, long type)
  738. {
  739.     // Even though ODF allows only 1 scroller view (the content view) we can't ignore
  740.     // additional scrollers which may be used for custom views, like CScrollEdit in Form.
  741.     // The important thing will be to delete it later (see CPPobScrollEdit::CreateODFView)
  742. /*
  743.     FW_CFrame* frame = FW_CPPobReader::gDefaultSuperView->GetFrame(ev);
  744.     if (frame->GetScroller(ev) != 0)
  745.     {
  746.         PPOB_WARNING("PPobReader Warning: This frame already has a scroller view");
  747.         return 0;
  748.     }
  749. */    
  750.     return (new FW_CPPobScrollBarScroller(ev, stream, (type == 'ascr')));
  751. }
  752.  
  753. //----------------------------------------------------------------------------------------
  754. //    FW_CPPobScrollBarScroller::CreateODFView
  755. //----------------------------------------------------------------------------------------
  756.  
  757. void    FW_CPPobScrollBarScroller::CreateODFView(Environment* ev)
  758. {
  759.     // Create the scroll bars first
  760.  
  761.     FW_CSuperView* superview = FW_CPPobReader::gDefaultSuperView;
  762.     FW_CScrollBar* horzSB = 0;
  763.     if (fHorizBarLeftIndent >= 0)
  764.     {    
  765.         FW_CRect bounds = fBounds;
  766.         bounds.left += FW_IntToFixed(fHorizBarLeftIndent);
  767.         bounds.right -= FW_IntToFixed(fHorizBarRightIndent);
  768.         bounds.top = bounds.bottom - FW_IntToFixed(16);
  769.  
  770.         horzSB = FW_NEW(FW_CScrollBar, (ev, superview, bounds, 'horz'));        
  771.     }
  772.  
  773.     FW_CScrollBar* vertSB = 0;
  774.     if (fVertBarTopIndent >= 0)
  775.     {    
  776.         FW_CRect bounds = fBounds;
  777.         bounds.top += FW_IntToFixed(fVertBarTopIndent);
  778.         bounds.bottom -= FW_IntToFixed(fVertBarBottomIndent);
  779.         bounds.left = bounds.right - FW_IntToFixed(16);
  780.  
  781.         vertSB = FW_NEW(FW_CScrollBar, (ev, superview, bounds, 'vert'));        
  782.     }
  783.     
  784.     // Create the ODF scroller.  Keep global for AdoptScroller later.  
  785.     FW_CFrame* frame = FW_CPPobReader::gDefaultSuperView->GetFrame(ev);
  786.     FW_CPPobReader::gScroller->fODFScroller = FW_NEW(FW_CScrollBarScroller, 
  787.                                         (ev, frame, fLiveScrolling, horzSB, vertSB));
  788.     
  789.     // Don't delete this FW_CPPobScrollBarScroller here, we do need it for the
  790.     // creation of the content view later...
  791. }
  792.  
  793. //----------------------------------------------------------------------------------------
  794. //    FW_CPPobListBox::FW_CPPobListBox
  795. //----------------------------------------------------------------------------------------
  796. FW_DEFINE_AUTO(FW_CPPobListBox)
  797.  
  798. FW_CPPobListBox::FW_CPPobListBox(Environment*ev, FW_CReadableStream& stream) :
  799.     FW_CPPobView(ev, stream)
  800. {    
  801.     SListBoxInfo    listInfo;
  802.     stream.Read(&listInfo, sizeof(SListBoxInfo));
  803.  
  804.     // Horizontal SB and custom LDEF are not supported
  805.     fNumRows = listInfo.numberOfItems;
  806.     fScrollVert = listInfo.hasVertScroll;
  807.     fTextTraitsID = listInfo.textTraitsID;
  808.     fDoubleClickMsg = listInfo.doubleClickMessage;
  809.     fSingleSelection = (listInfo.hasGrow == 0);    // HACK: use Grow box for this flag...
  810.     fUseFocusFrame = listInfo.hasFocusBox;
  811.     
  812.     // Read the string items.
  813.     // [LSD] we ignore these strings for now. Anyway they cannot be entered in Constructor
  814.     //        one need a Rez or Resourcerer template
  815.     for (int i = 0; i < fNumRows; i++)
  816.     {
  817.         FW_CString item = FW_CPPobReader::ReadStr255(stream);
  818.     }
  819. }
  820.  
  821. //----------------------------------------------------------------------------------------
  822. //    FW_CPPobListBox::Create
  823. //----------------------------------------------------------------------------------------
  824.  
  825. void*    FW_CPPobListBox::Create(Environment*ev, FW_CReadableStream& stream, long type)
  826. {
  827. FW_UNUSED(type);
  828.     return FW_NEW(FW_CPPobListBox, (ev, stream));
  829. }
  830.  
  831. //----------------------------------------------------------------------------------------
  832. //    FW_CPPobListBox::CreateODFView
  833. //----------------------------------------------------------------------------------------
  834.  
  835. void    FW_CPPobListBox::CreateODFView(Environment* ev)
  836. {
  837.     FW_TextBoxOptions options;
  838.     FW_CFont font;
  839.     FW_CColor color;
  840.     FW_CPPobReader::GetTextTraits(fTextTraitsID, font, options, color);
  841.     
  842.     // Create the ODF listbox
  843.     FW_CListBox* view = FW_NEW(FW_CListBox, (ev, fSuperView, fBounds, fViewID, fNumRows, 
  844.                 fScrollVert, font, fDoubleClickMsg, fSingleSelection, fUseFocusFrame, false));
  845.     view->SetBindings(ev, fBindings);
  846.  
  847.     delete this;    // we don't need you anymore...
  848. }
  849.  
  850. //----------------------------------------------------------------------------------------
  851. //    FW_CPPobPictSView::FW_CPPobPictSView
  852. //----------------------------------------------------------------------------------------
  853.  
  854. FW_CPPobPictSView::FW_CPPobPictSView(Environment*ev, FW_CReadableStream& stream, long type) :
  855.     FW_CPPobSuperView(ev, stream)
  856. {
  857. FW_UNUSED(type);
  858.     stream >> fPictID;
  859. }
  860.  
  861. //----------------------------------------------------------------------------------------
  862. //    FW_CPPobPictSView::Create
  863. //----------------------------------------------------------------------------------------
  864.  
  865. void*    FW_CPPobPictSView::Create(Environment*ev, FW_CReadableStream& stream, long type)
  866. {
  867.     return (new FW_CPPobPictSView(ev, stream, type));
  868. }
  869.  
  870. //----------------------------------------------------------------------------------------
  871. //    FW_CPPobPictSView::CreateODFView
  872. //----------------------------------------------------------------------------------------
  873.  
  874. void    FW_CPPobPictSView::CreateODFView(Environment* ev)
  875. {
  876.     // Load the Mac picture resource manually instead of using FW_CPicture API because
  877.     // we don't have the resource file here
  878.     FW_PlatformPict    macPictHdl = ::GetPicture(fPictID);
  879.     FW_CPictSView* view;
  880.     
  881.     if (macPictHdl)
  882.     {
  883.         // Must detach the resource manually because we loaded it manually
  884.         ::DetachResource((Handle)macPictHdl);
  885.         
  886.         // Create the FW_CPictSView view
  887.         view = FW_NEW(FW_CPictSView, (ev, fSuperView, fBounds, fViewID, 
  888.                                                     FW_CPicture(macPictHdl)));
  889.     }
  890.     else
  891.     {
  892.         // If the picture cannot be loaded here we create a FW_CPictSView with the same
  893.         // pict ID, the FW_CPictSView class will display an error message
  894.         view = FW_NEW(FW_CPictSView, (ev, fSuperView, fBounds, fViewID, fPictID));
  895.     }
  896.     view->SetBindings(ev, fBindings);
  897.     
  898.     // Important: all superview classes must call PostCreateODFView before returning
  899.     PostCreateODFView(ev, view);
  900.  
  901.     delete this;    // we don't need you anymore...
  902. }
  903.  
  904. //----------------------------------------------------------------------------------------
  905. //    FW_CPPobUnknownView::FW_CPPobUnknownView
  906. //----------------------------------------------------------------------------------------
  907.  
  908. FW_CPPobUnknownView::FW_CPPobUnknownView(Environment*ev, FW_CReadableStream& stream, long type) :
  909.     FW_CPPobView(ev, stream),
  910.     fClassID(type)
  911. {
  912. }
  913.  
  914. //----------------------------------------------------------------------------------------
  915. //    FW_CPPobUnknownView::CreateODFView
  916. //----------------------------------------------------------------------------------------
  917.  
  918. void    FW_CPPobUnknownView::CreateODFView(Environment* ev)
  919. {
  920.     FW_CString className((char*)&fClassID, 4);
  921.     
  922.     FW_CUnknownView* view = FW_NEW(FW_CUnknownView, (ev, fSuperView, fViewID, fBounds, className));
  923.     view->SetBindings(ev, fBindings);
  924.  
  925.     delete this;    // we don't need you anymore...
  926. }
  927.  
  928. //----------------------------------------------------------------------------------------
  929. //    FW_CPPobUnknownSView::FW_CPPobUnknownSView
  930. //----------------------------------------------------------------------------------------
  931.  
  932. FW_CPPobUnknownSView::FW_CPPobUnknownSView(Environment*ev, FW_CReadableStream& stream, long type) :
  933.     FW_CPPobSuperView(ev, stream),
  934.     fClassID(type)
  935. {
  936. }
  937.  
  938. //----------------------------------------------------------------------------------------
  939. //    FW_CPPobUnknownSView::CreateODFView
  940. //----------------------------------------------------------------------------------------
  941.  
  942. void    FW_CPPobUnknownSView::CreateODFView(Environment* ev)
  943. {
  944.     FW_CString className((char*)&fClassID, 4);
  945.  
  946.     FW_CUnknownView* view = FW_NEW(FW_CUnknownView, (ev, fSuperView, fViewID, fBounds, 
  947.                                             fExtent, fScrollingDirection, className));
  948.     view->SetBindings(ev, fBindings);
  949.  
  950.     PostCreateODFView(ev, view);
  951.  
  952.     delete this;    // we don't need you anymore...
  953. }
  954.  
  955. //----------------------------------------------------------------------------------------
  956. //    FW_CPPobRadioCluster::Create
  957. //----------------------------------------------------------------------------------------
  958. // Radio groups are not views, we read the stream and create the ODF cluster directly
  959.  
  960. void*    FW_CPPobRadioCluster::Create(Environment*ev, FW_CReadableStream& stream, long type)
  961. {
  962. FW_UNUSED(type);
  963.     short numRadios;
  964.     stream >> numRadios;
  965.  
  966.     FW_CRadioCluster* radioCluster = FW_NEW(FW_CRadioCluster, (ev));
  967.     FW_CSuperView* superview = FW_CPPobReader::gDefaultSuperView;
  968.     
  969.     for (int i = 0; i < numRadios; i++)
  970.     {
  971.         PaneIDT        radioID;
  972.         stream >> radioID;
  973.  
  974.         FW_CView* view = superview->FindViewByID(ev, radioID);
  975.         FW_CButton* button = FW_DYNAMIC_CAST(FW_CButton, view);        
  976.         radioCluster->AddRadio(ev, button);
  977.     }
  978.     
  979.     return 0;    // Return null object to by-pass CreateODFView method
  980. }
  981.  
  982. //----------------------------------------------------------------------------------------
  983. //    FW_CPPobViewTabber::Create
  984. //----------------------------------------------------------------------------------------
  985. // Tab groups are not views, we create the ODF tabber directly
  986.  
  987. void*    FW_CPPobViewTabber::Create(Environment*ev, FW_CReadableStream& stream, long type)
  988. {
  989. FW_UNUSED(stream);
  990. FW_UNUSED(type);
  991.     FW_CViewTabber* viewTabber = new FW_CViewTabber(ev, FW_CPPobReader::gDefaultSuperView);    
  992.  
  993.     return 0;    // Return null object to by-pass CreateODFView method
  994. }
  995.  
  996.  
  997.  
  998.